package com.dy.design_pattern_study.state_pattern.dome1;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-06
 * @Content
 */
public class firstDome {

    public static void main(String[] args) {
        hour = 9;
        writeProgram();
        hour = 10;
        writeProgram();
        hour = 12;
        writeProgram();
        hour = 13;
        writeProgram();
        hour = 14;
        writeProgram();
        hour = 17;
        writeProgram();

        workFinished = true;
        writeProgram();

        hour = 19;
        writeProgram();
        hour = 22;
        writeProgram();

    }

    static int hour = 0;//时间
    static boolean workFinished = false;//任务完成标记

    public static void writeProgram(){
        /*
            状态模式就是把 以下的if-else 都给整合成单个 if-else
            尽可能的减少if-else 的长度
         */
        if (hour < 12){
            System.out.println("上午工作，精神满满：时间 hour = " + hour);
        }else if (hour < 13){
            System.out.println("中午时间 hour = " + hour);
        }else if (hour < 17){
            System.out.println("下午时间，hour = " + hour);
        } else {
            if (workFinished){
                System.out.println("任务完成，下班回家，hour = " + hour);
            }else {
                if (hour < 21){
                    System.out.println("任务未完成，继续加班，hour = " + hour);
                }else {
                    System.out.println("精力有限，无法坚持，hour = " + hour);
                }
            }
        }
    }



}
